package com.clstu.algrithm;

/**
 * 研究kmp算法
 */
public class KMPAlgrithm {
    public static void main(String[] args) {
        String father = "hello world !!";
        String son = "hello ";
        System.out.println(match(father,son));
    }

    //编写反复实现暴力匹配,找到子串下标
    public static int match(String s1,String s2){
        char[] father = s1.toCharArray();//父串
        char[] son = s2.toCharArray();//子串
        //思路分析暴力匹配
        for (int i = 0; i < father.length; i++) {
            for (int j = 0; j < son.length; j++) {
                //如果不匹配,
                if(father[i+j]!=son[j]){
                    break;
                }
                //如果匹配成功
                if(j==son.length-1){
                    return i;
                }
            }
        }
        //否则就是匹配失败
        return -1;
    }

    //编写反复实现kmp算法
    public static int KMP(){
        return -1;
    }
}
